package com.party.core.service.material.impl;

import com.party.common.paging.Page;
import com.party.core.dao.read.material.MaterialMemberReadDao;
import com.party.core.dao.write.material.MaterialMemberWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.material.MaterialMember;
import com.party.core.service.material.IMaterialMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @program: party
 * @description: 素材管理服务接口实现
 * @author: Hua Qunhao
 * @create: 2019-12-10 13:54
 **/
@Service
public class MaterialMemberService implements IMaterialMemberService {

    @Autowired
    private MaterialMemberReadDao materialMemberReadDao;
    @Autowired
    private MaterialMemberWriteDao materialMemberWriteDao;

    @Override
    public String insert(MaterialMember materialMember) {
        BaseModel.preInsert(materialMember);
        boolean result = materialMemberWriteDao.insert(materialMember);
        if (result) {
            return materialMember.getId();
        }
        return null;
    }

    @Override
    public boolean update(MaterialMember materialMember) {
        materialMember.setUpdateDate(new Date());
        return materialMemberWriteDao.update(materialMember);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        return materialMemberWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return false;
    }

    @Override
    public MaterialMember get(String id) {
        return materialMemberReadDao.get(id);
    }

    @Override
    public List<MaterialMember> listPage(MaterialMember materialMember, Page page) {
        return materialMemberReadDao.listPage(materialMember, page);
    }

    @Override
    public List<MaterialMember> list(MaterialMember materialMember) {
        return materialMemberReadDao.listPage(materialMember, null);
    }

    @Override
    public List<MaterialMember> batchList(Set<String> ids, MaterialMember materialMember, Page page) {
        return null;
    }

    @Override
    public void deleteByUnique(String articleId, String memberId) {
        materialMemberWriteDao.deleteByUnique(articleId, memberId);
    }

    @Override
    public void deleteByArticleId(String articleId) {
        materialMemberWriteDao.deleteByArticleId(articleId);
    }
}
